package com.luoye.lj.wstool.generator;

import com.luoye.lj.wstool.common.MysqlDbConfig;
import com.luoye.lj.wstool.common.StringUtils;
import com.luoye.lj.wstool.wsdm.*;
import com.luoye.lj.wstool.wsdm.ConstructorCodeGenerator;
import com.luoye.lj.wstool.wsdm.FieldsCodeGenerator;
import com.luoye.lj.wstool.wsdm.ToStringCodeGenerator;
import com.luoye.lj.wstool.wsdm.entity.WsdtEntity;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/*
 * Created with IntelliJ IDEA.
 * User: Dave Liu
 * Date: 2020/2/10
 * Time: 16:33
 * To change this template use File | Settings | File Templates.
 */
public class WsdmGenerator{
    private MysqlDbConfig dbConfig;

    public WsdmGenerator(MysqlDbConfig dbConfig) {
        this.dbConfig = dbConfig;
    }

    public void execute() {

        String baseDir=System.getProperty("user.dir");//this.getClass().getResource("/").getPath();
        //String baseDir=getBasedir().getAbsolutePath();
        System.out.println("项目基础目录为："+baseDir);


        //提示用户输入表名
        String tableNameStr=null;
        BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
        do {
            System.out.println("请输入表名，退出请输入q：");
            try {
                tableNameStr = bufferedReader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }while ("".equals(tableNameStr.trim()));
        if("q".equals(tableNameStr)){
            return;
        }

        //提示用户输入模型
        String model="wsdm";
//        bufferedReader=new BufferedReader(new InputStreamReader(System.in));
//        do {
//            System.out.println("请输入表名，退出请输入q：");
//            try {
//                model = bufferedReader.readLine();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//            model=model.trim();
//        }while (!("sdm".equals(model) || "dm".equals(model) || "m".equals(model) || "e".equals(model)  || "q".equals(model)));
//        if("q".equals(model)){//退出
//            return;
//        }

        //解析
        WsdtEntity wsdtEntity= TtoEntityResolver.resolve(dbConfig,tableNameStr);
        System.out.println("wsdtEntity->"+wsdtEntity);
        if(wsdtEntity==null){
            return;
        }

        String baseJavaDir=baseDir+"/src/main/java/";

        String basePackageName="com.luoye.lj";
        String basePackageDir=basePackageName.replaceAll("\\.","\\/");
        System.out.println("basePackageDir->"+basePackageDir);

        String entityFullDir=baseJavaDir+basePackageDir+"/pojo/dbo/";
        System.out.println("entityFullDir->"+entityFullDir);
        String tempDir=baseJavaDir+"com/luoye/lj/wstool/wsdm/temp/";

        //生成实体相关文件
        String packageName=basePackageName+".pojo.dbo";
        wsdtEntity.setEntityPackageName(packageName);
        FileGenerator fileGenerator=new FileGenerator();
        //生成实体类
        String templatePath= baseJavaDir+"com/luoye/lj/wstool/wsdm/temp/Entity.jtemp";
        String targetPath=entityFullDir+wsdtEntity.getEntityName()+"Dbo.java";
        fileGenerator.addReplaceStr("packageName",packageName);
        fileGenerator.addReplaceStr("entityName",wsdtEntity.getEntityName()+"Dbo");
        fileGenerator.addReplaceStr("entityFieldsCode",new FieldsCodeGenerator(wsdtEntity).codeGenerate());
        fileGenerator.addReplaceStr("entityString",new ToStringCodeGenerator(wsdtEntity).codeGenerate());
        fileGenerator.addReplaceStr("constructor",new ConstructorCodeGenerator(wsdtEntity,"Dbo").codeGenerate());
        fileGenerator.generate(templatePath,targetPath);
        //生成实体集合类
        fileGenerator.clearReplaceStrs();
        templatePath= baseJavaDir+"com/luoye/lj/wstool/wsdm/temp/EntityCollection.jtemp";
        targetPath=entityFullDir+wsdtEntity.getEntityName()+"DboCollection.java";
        fileGenerator.addReplaceStr("packageName",packageName);
        fileGenerator.addReplaceStr("entityName",wsdtEntity.getEntityName()+"Dbo");
        fileGenerator.generate(templatePath,targetPath);
        //生成实体搜索条件类
        fileGenerator.clearReplaceStrs();
        templatePath= baseJavaDir+"com/luoye/lj/wstool/wsdm/temp/EntitySearchCondition.jtemp";
        targetPath=entityFullDir+wsdtEntity.getEntityName()+"DboSearchCondition.java";
        fileGenerator.addReplaceStr("packageName",packageName);
        fileGenerator.addReplaceStr("entityName",wsdtEntity.getEntityName()+"Dbo");
        fileGenerator.addReplaceStr("entityFieldsCode",new FieldsCodeGenerator(wsdtEntity).codeGenerate());
        fileGenerator.addReplaceStr("entityString",new ToStringCodeGenerator(wsdtEntity).codeGenerate());
        fileGenerator.addReplaceStr("constructor",new ConstructorCodeGenerator(wsdtEntity,"DboSearchCondition").codeGenerate());
        fileGenerator.generate(templatePath,targetPath);

        String baseResourceDir=baseDir+"/src/main/resources/";

//        String serviceResourcesDir = baseResourceDir+"mapper" + basePackageDir + "";
        //String serviceJavaDir = baseJavaDir+basePackageDir + "";
        String serviceJavaDaoDir = baseJavaDir+basePackageDir + "/dao";
        String mapperInterfaceName = "I" + StringUtils.makeFirstCharUpcase(wsdtEntity.getEntityName()) + "Mapper";
        //生成mapper
        if(model.contains("m")) {
//            String serviceResourcesDaoDir = serviceResourcesDir + "/dao";
            String nameSpace = basePackageName + ".dao.mapper." + mapperInterfaceName;
            String name = mapperInterfaceName;
            fileGenerator.clearReplaceStrs();
            fileGenerator.addReplaceStr("nameSpace", nameSpace);
            fileGenerator.addReplaceStr("entityFullName", wsdtEntity.getEntityPackageName() + "." + wsdtEntity.getEntityName()+"Dbo");
            fileGenerator.addReplaceStr("entityInstance", StringUtils.makeFirstCharLowercase(wsdtEntity.getEntityName()+"Dbo"));
            fileGenerator.addReplaceStr("entityMap", new EntityMapCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("insertSql", new InsertSqlCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("deleteSql", new DeleteSqlCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("updateSql", new UpdateSqlCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("getSql", new GetSqlCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("countByConditionSql", new CountByConditionSqlCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("searchByConditionSql", new SearchByConditionSqlCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("deleteByConditionSql", new DeleteByConditionSqlCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("statisticsByConditionSql", new StatisticsByConditionSqlCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("getMaxIdSql", new GetMaxIdSqlCodeGenerator(wsdtEntity));
            templatePath = baseJavaDir+"com/luoye/lj/wstool/wsdm/temp/MapperTemplate.xtemp";
            targetPath = baseResourceDir + "mapper/" + name + ".xml";
            fileGenerator.generate(templatePath, targetPath);

            packageName = basePackageName + ".dao.mapper";
            name = mapperInterfaceName;
            fileGenerator.clearReplaceStrs();
            fileGenerator.addReplaceStr("packageName", packageName);
            fileGenerator.addReplaceStr("entityPackageName", wsdtEntity.getEntityPackageName());
            fileGenerator.addReplaceStr("entityName", wsdtEntity.getEntityName()+"Dbo");
            fileGenerator.addReplaceStr("name", name);
            fileGenerator.addReplaceStr("entityInstance", StringUtils.makeFirstCharLowercase(wsdtEntity.getEntityName()+"Dbo"));
            fileGenerator.addReplaceStr("primaryParam", new PrimaryParamCodeGenerator(wsdtEntity));
            templatePath = baseJavaDir+"com/luoye/lj/wstool/wsdm/temp/IMapperTemplate.jtemp";
            targetPath = serviceJavaDaoDir + "/mapper/" + name + ".java";
            fileGenerator.generate(templatePath, targetPath);
        }
        if(model.contains("d")) {
            //生成dao
            packageName = basePackageName + ".dao";
            String name = "I" + StringUtils.makeFirstCharUpcase(wsdtEntity.getEntityName()) + "Dao";
            fileGenerator.clearReplaceStrs();
            fileGenerator.addReplaceStr("packageName", packageName);
            fileGenerator.addReplaceStr("entityPackageName", wsdtEntity.getEntityPackageName());
            fileGenerator.addReplaceStr("entityName", wsdtEntity.getEntityName()+"Dbo");
            fileGenerator.addReplaceStr("name", name);
            fileGenerator.addReplaceStr("entityInstance", StringUtils.makeFirstCharLowercase(wsdtEntity.getEntityName()+"Dbo"));
            fileGenerator.addReplaceStr("primaryParam", new PrimaryParamCodeGenerator(wsdtEntity, false));
            templatePath = baseJavaDir+"com/luoye/lj/wstool/wsdm/temp/ITempInfoDao.jtemp";
            targetPath = serviceJavaDaoDir + "/" + name + ".java";
            fileGenerator.generate(templatePath, targetPath);

            packageName = basePackageName + ".dao.impl";
            name = StringUtils.makeFirstCharUpcase(wsdtEntity.getEntityName()) + "DaoImpl";
            String interfaceName = "I" + StringUtils.makeFirstCharUpcase(wsdtEntity.getEntityName()) + "Dao";
            String interfaceFullName = basePackageName + ".dao." + interfaceName;
            //String mapperInterfaceName="I"+ StringUtils.makeFirstCharUpcase(projectArtifactIdSimple)+"Mapper";
            String mapperInterfaceFullName = basePackageName + ".dao.mapper." + mapperInterfaceName;
            String mapperName = StringUtils.makeFirstCharLowercase(wsdtEntity.getEntityName()) + "Mapper";
            fileGenerator.clearReplaceStrs();
            fileGenerator.addReplaceStr("packageName", packageName);
            fileGenerator.addReplaceStr("name", name);
            fileGenerator.addReplaceStr("interfaceFullName", interfaceFullName);
            fileGenerator.addReplaceStr("mapperInterfaceFullName", mapperInterfaceFullName);
            fileGenerator.addReplaceStr("interfaceName", interfaceName);
            fileGenerator.addReplaceStr("mapperInterfaceName", mapperInterfaceName);
            fileGenerator.addReplaceStr("mapperName", mapperName);
            fileGenerator.addReplaceStr("entityPackageName", wsdtEntity.getEntityPackageName());
            fileGenerator.addReplaceStr("entityName", wsdtEntity.getEntityName()+"Dbo");
            fileGenerator.addReplaceStr("entityInstance", StringUtils.makeFirstCharLowercase(wsdtEntity.getEntityName()+"Dbo"));
            fileGenerator.addReplaceStr("primaryParam", new PrimaryParamCodeGenerator(wsdtEntity, false));
            fileGenerator.addReplaceStr("primaryParamNoType", new PrimaryParamCodeGenerator(wsdtEntity, false, false));
            templatePath = baseJavaDir+"com/luoye/lj/wstool/wsdm/temp/TempInfoDaoImpl.jtemp";
            targetPath = serviceJavaDaoDir + "/impl/" + name + ".java";
            fileGenerator.generate(templatePath, targetPath);
        }

        if(model.contains("s")) {
            //生成service
            packageName = basePackageName + ".service";
            String name = "I" + StringUtils.makeFirstCharUpcase(wsdtEntity.getEntityName()) + "Service";
            templatePath = baseJavaDir+"com/luoye/lj/wstool/wsdm/temp/IServiceTemp.jtemp";
            targetPath = baseJavaDir+basePackageDir + "/service/" + name + ".java";
            fileGenerator.clearReplaceStrs();
            fileGenerator.addReplaceStr("packageName", packageName);
            fileGenerator.addReplaceStr("entityPackageName", wsdtEntity.getEntityPackageName());
            fileGenerator.addReplaceStr("entityName", wsdtEntity.getEntityName()+"Dbo");
            fileGenerator.addReplaceStr("name", name);
            fileGenerator.addReplaceStr("entityInstance", StringUtils.makeFirstCharLowercase(wsdtEntity.getEntityName()+"Dbo"));
            fileGenerator.addReplaceStr("primaryParam", new PrimaryParamCodeGenerator(wsdtEntity, false));
            fileGenerator.generate(templatePath, targetPath);

            String serviceJavaServiceDir = baseJavaDir+basePackageDir + "/service";
            packageName = basePackageName + ".service.impl";
            name = StringUtils.makeFirstCharUpcase(wsdtEntity.getEntityName()) + "ServiceImpl";
            String interfaceName = "I" + StringUtils.makeFirstCharUpcase(wsdtEntity.getEntityName()) + "Service";
            String interfaceFullName = basePackageName + ".service." + interfaceName;
            String daoInterfaceName = "I" + StringUtils.makeFirstCharUpcase(wsdtEntity.getEntityName()) + "Dao";
            String daoInterfaceFullName = basePackageName + ".dao." + daoInterfaceName;
            String daoName = StringUtils.makeFirstCharLowercase(wsdtEntity.getEntityName()) + "Dao";
            String serviceExceptionConstantsFullName=basePackageName + ".constant.ServiceExceptionConstants";
            fileGenerator.clearReplaceStrs();
            fileGenerator.addReplaceStr("packageName", packageName);
            fileGenerator.addReplaceStr("name", name);
            fileGenerator.addReplaceStr("interfaceName", interfaceName);
            fileGenerator.addReplaceStr("interfaceFullName", interfaceFullName);
            fileGenerator.addReplaceStr("daoInterfaceFullName", daoInterfaceFullName);
            fileGenerator.addReplaceStr("daoInterfaceName", daoInterfaceName);
            fileGenerator.addReplaceStr("daoName", daoName);
            fileGenerator.addReplaceStr("entityPackageName", wsdtEntity.getEntityPackageName()+"");
            fileGenerator.addReplaceStr("entityName", wsdtEntity.getEntityName()+"Dbo");
            fileGenerator.addReplaceStr("entityInstance", StringUtils.makeFirstCharLowercase(wsdtEntity.getEntityName()+"Dbo"));
            fileGenerator.addReplaceStr("primaryParam", new PrimaryParamCodeGenerator(wsdtEntity, false));
            fileGenerator.addReplaceStr("primaryParamNoType", new PrimaryParamCodeGenerator(wsdtEntity, false, false));
//            fileGenerator.addReplaceStr("serviceExceptionConstantsFullName",serviceExceptionConstantsFullName);

            templatePath = baseJavaDir+"com/luoye/lj/wstool/wsdm/temp/TempServiceImpl.jtemp";
            targetPath = serviceJavaServiceDir + "/impl/" + name + ".java";
            fileGenerator.generate(templatePath, targetPath);
        }

        if(model.contains("w")) {
            //生成实体相关文件
            //Vo
            packageName=basePackageName+".pojo.vo";
            wsdtEntity.setEntityPackageName(packageName);
            fileGenerator=new FileGenerator();
            //生成实体类
            entityFullDir=baseJavaDir+basePackageDir+"/pojo/vo/";
            templatePath= baseJavaDir+"com/luoye/lj/wstool/wsdm/temp/Entity.jtemp";
            targetPath=entityFullDir+wsdtEntity.getEntityName()+"Vo.java";
            fileGenerator.addReplaceStr("packageName",packageName);
            fileGenerator.addReplaceStr("entityName",wsdtEntity.getEntityName()+"Vo");
            fileGenerator.addReplaceStr("entityFieldsCode",new FieldsCodeGenerator(wsdtEntity).codeGenerate());
            fileGenerator.addReplaceStr("entityString",new ToStringCodeGenerator(wsdtEntity).codeGenerate());
            fileGenerator.addReplaceStr("constructor",new ConstructorCodeGenerator(wsdtEntity,"Vo").codeGenerate());
            fileGenerator.generate(templatePath,targetPath);
            //生成实体集合类
            fileGenerator.clearReplaceStrs();
            templatePath= baseJavaDir+"com/luoye/lj/wstool/wsdm/temp/EntityCollection.jtemp";
            targetPath=entityFullDir+wsdtEntity.getEntityName()+"VoCollection.java";
            fileGenerator.addReplaceStr("packageName",packageName);
            fileGenerator.addReplaceStr("entityName",wsdtEntity.getEntityName()+"Vo");
            fileGenerator.generate(templatePath,targetPath);

            //Dto
            packageName=basePackageName+".pojo.dto";
            wsdtEntity.setEntityPackageName(packageName);
            fileGenerator=new FileGenerator();
            //生成实体类
            entityFullDir=baseJavaDir+basePackageDir+"/pojo/dto/";
            templatePath= baseJavaDir+"com/luoye/lj/wstool/wsdm/temp/Entity.jtemp";
            targetPath=entityFullDir+wsdtEntity.getEntityName()+"Dto.java";
            fileGenerator.addReplaceStr("packageName",packageName);
            fileGenerator.addReplaceStr("entityName",wsdtEntity.getEntityName()+"Dto");
            fileGenerator.addReplaceStr("entityFieldsCode",new FieldsCodeGenerator(wsdtEntity).codeGenerate());
            fileGenerator.addReplaceStr("entityString",new ToStringCodeGenerator(wsdtEntity).codeGenerate());
            fileGenerator.addReplaceStr("constructor",new ConstructorCodeGenerator(wsdtEntity,"Dto").codeGenerate());
            fileGenerator.generate(templatePath,targetPath);
            //生成实体搜索条件类
            fileGenerator.clearReplaceStrs();
            templatePath= baseJavaDir+"com/luoye/lj/wstool/wsdm/temp/EntitySearchCondition.jtemp";
            targetPath=entityFullDir+wsdtEntity.getEntityName()+"DtoSearchCondition.java";
            fileGenerator.addReplaceStr("packageName",packageName);
            fileGenerator.addReplaceStr("entityName",wsdtEntity.getEntityName()+"Dto");
            fileGenerator.addReplaceStr("entityFieldsCode",new FieldsCodeGenerator(wsdtEntity).codeGenerate());
            fileGenerator.addReplaceStr("entityString",new ToStringCodeGenerator(wsdtEntity).codeGenerate());
            fileGenerator.addReplaceStr("constructor",new ConstructorCodeGenerator(wsdtEntity,"DtoSearchCondition").codeGenerate());
            fileGenerator.generate(templatePath,targetPath);

            //生成controller
            packageName = basePackageName + ".controller";
            String controllerDir=baseJavaDir+basePackageDir + "/controller";
            String controllerFullPath=controllerDir+"/"+wsdtEntity.getEntityName()+"Controller.java";
            fileGenerator.clearReplaceStrs();
            templatePath=  baseJavaDir+"com/luoye/lj/wstool/wsdm/temp/EntityController.jtemp";
            targetPath=controllerFullPath;
            fileGenerator.addReplaceStr("packageName",packageName);
            fileGenerator.addReplaceStr("name",wsdtEntity.getEntityName()+"Controller");
            fileGenerator.addReplaceStr("webPath","/bll/"+ StringUtils.makeFirstCharLowercase(wsdtEntity.getEntityName()));
            fileGenerator.addReplaceStr("entityName",wsdtEntity.getEntityName());
            fileGenerator.addReplaceStr("entityInstance",StringUtils.makeFirstCharLowercase(wsdtEntity.getEntityName()));
//            fileGenerator.addReplaceStr("wsPath",wsdtEntity.getPath());
            fileGenerator.addReplaceStr("jspDir","bll/"+StringUtils.makeFirstCharLowercase(wsdtEntity.getEntityName()));
            fileGenerator.addReplaceStr("voPackage",basePackageName+".pojo.vo");
            fileGenerator.addReplaceStr("dtoPackage",basePackageName+".pojo.dto");
            fileGenerator.addReplaceStr("dboPackage",basePackageName+".pojo.dbo");
            fileGenerator.addReplaceStr("servicePackage",basePackageName+".service");
            fileGenerator.addReplaceStr("entityDescription",wsdtEntity.getDescription());
            fileGenerator.addReplaceStr("showFieldListAddCode",new ShowFieldListAddCodeGenerator(wsdtEntity).codeGenerate());
            fileGenerator.addReplaceStr("fieldEntitiesImport",new FieldEntityServicesImportGenerator(wsdtEntity).codeGenerate());
            fileGenerator.addReplaceStr("fieldEntityServiceInjection",new FieldEntityServicesInjectionGenerator(wsdtEntity).codeGenerate());
            fileGenerator.addReplaceStr("fieldEntitiesModel",new FieldEntityModelsGenerator(wsdtEntity).codeGenerate());
            if(wsdtEntity.getWsdtEntityDesc()!=null) {
                fileGenerator.addReplaceStr("entityTitle", wsdtEntity.getWsdtEntityDesc().getTitleText());
            }else{
                fileGenerator.addReplaceStr("entityTitle", wsdtEntity.getDescription()+"列表");
            }
            if(wsdtEntity.getWsdtEntityDesc()==null){
                fileGenerator.addReplaceStr("exportExcelStatistic","true");
            }else{
                if(wsdtEntity.getWsdtEntityDesc().isExportExcel()&&wsdtEntity.getWsdtEntityDesc().isExportExcelStatistic()) {//导出统计
                    fileGenerator.addReplaceStr("exportExcelStatistic", "true");
                }else{
                    fileGenerator.addReplaceStr("exportExcelStatistic", "false");
                }
            }
            fileGenerator.generate(templatePath,targetPath);


            //生成html
            String htmlFullPath=baseResourceDir+"/templates/bll/"+StringUtils.makeFirstCharLowercase(wsdtEntity.getEntityName())+"/"+StringUtils.makeFirstCharLowercase(wsdtEntity.getEntityName())+"_list.html";
            System.out.println("htmlFullPath->"+htmlFullPath);
            fileGenerator.clearReplaceStrs();
            templatePath= baseJavaDir+"com/luoye/lj/wstool/wsdm/temp/EntityList.htmt";
            targetPath=htmlFullPath;
            fileGenerator.addReplaceStr("webPath","/bll/"+ StringUtils.makeFirstCharLowercase(wsdtEntity.getEntityName()));
            fileGenerator.addReplaceStr("searchData",new HtmlDataCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("dataFields",new HtmlFieldsCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("editSet",new HtmlEditSetCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("saveData",new HtmlSaveDataCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("addSet",new HtmlAddSetCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("searchTarget",new HtmlSearchTargetCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("editTarget",new HtmlEditTargetCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("entityDescription",wsdtEntity.getDescription());
            fileGenerator.addReplaceStr("searchParams",new HtmlParamsCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("exportFieldsForSelect",new HtmlExportFieldsForSelectCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("importFieldsForSelect",new HtmlImportFieldsForSelectCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("fieldEntityMap",new HtmlFieldEntityMapCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("statisticTarget",new HtmlStatisticTargetCodeGenerator(wsdtEntity));
            fileGenerator.addReplaceStr("statisticSet",new HtmlStatisticSetCodeGenerator(wsdtEntity));
            if(wsdtEntity.getWsdtEntityDesc()==null||wsdtEntity.getWsdtEntityDesc().isShowStatistic()){
                fileGenerator.addReplaceStr("hideStatistic","");
                fileGenerator.addReplaceStr("doStatistic","true");
            }else{
                fileGenerator.addReplaceStr("hideStatistic","style=\"display: none;\"");
                fileGenerator.addReplaceStr("doStatistic","false");
            }
            if(wsdtEntity.getWsdtEntityDesc()==null||wsdtEntity.getWsdtEntityDesc().isAdd()){
                fileGenerator.addReplaceStr("hideAdd","");
            }else{
                fileGenerator.addReplaceStr("hideAdd","style=\"display: none;\"");
            }
            if(wsdtEntity.getWsdtEntityDesc()==null||wsdtEntity.getWsdtEntityDesc().isImportExcel()){
                fileGenerator.addReplaceStr("hideImport","");
            }else{
                fileGenerator.addReplaceStr("hideImport","style=\"display: none;\"");
            }
            if(wsdtEntity.getWsdtEntityDesc()==null||wsdtEntity.getWsdtEntityDesc().isExportExcel()){
                fileGenerator.addReplaceStr("hideExport","");
            }else{
                fileGenerator.addReplaceStr("hideExport","style=\"display: none;\"");
            }
            if(wsdtEntity.getWsdtEntityDesc()==null||wsdtEntity.getWsdtEntityDesc().isDetail()){
                fileGenerator.addReplaceStr("showDetail","true");
            }else{
                fileGenerator.addReplaceStr("showDetail","false");
            }
            if(wsdtEntity.getWsdtEntityDesc()==null||wsdtEntity.getWsdtEntityDesc().isEdit()){
                fileGenerator.addReplaceStr("showEdit","true");
            }else{
                fileGenerator.addReplaceStr("showEdit","false");
            }
            if(wsdtEntity.getWsdtEntityDesc()==null||wsdtEntity.getWsdtEntityDesc().isCopy()){
                fileGenerator.addReplaceStr("showCopy","true");
            }else{
                fileGenerator.addReplaceStr("showCopy","false");
            }
            if(wsdtEntity.getWsdtEntityDesc()==null||wsdtEntity.getWsdtEntityDesc().isRemove()){
                fileGenerator.addReplaceStr("showRemove","true");
            }else{
                fileGenerator.addReplaceStr("showRemove","false");
            }

            fileGenerator.generate(templatePath,targetPath);


            //菜单和权限添加
            String menuName=wsdtEntity.getDescription();
            if(wsdtEntity.getWsdtEntityDesc()!=null){
                menuName=wsdtEntity.getWsdtEntityDesc().getMenuText();
            }
            String menuUrl="/bll/"+ StringUtils.makeFirstCharLowercase(wsdtEntity.getEntityName())+"/list";
            MenuAndAuthInserter.InsertMenu(dbConfig,menuName,menuUrl);

            String authName="A_Bll_"+wsdtEntity.getEntityName();
            String authDesc=wsdtEntity.getDescription()+"管理";
            String patterns="/bll/"+ StringUtils.makeFirstCharLowercase(wsdtEntity.getEntityName())+"/**";
            MenuAndAuthInserter.InsertAuth(dbConfig,authName,authDesc,patterns);

        }

    }
}
